<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>L2LB: cluster.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Gerado por Doxygen 1.5.6 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Página&nbsp;principal</span></a></li>
      <li><a href="annotated.html"><span>Estruturas&nbsp;de&nbsp;dados</span></a></li>
      <li class="current"><a href="files.html"><span>Ficheiros</span></a></li>
    </ul>
  </div>
<h1>cluster.h</h1><a href="cluster_8h.html">Ir para a documentação deste ficheiro.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00006"></a>00006 <span class="preprocessor">#ifndef CLUSTER_H_</span>
<a name="l00007"></a>00007 <span class="preprocessor"></span><span class="preprocessor">#define CLUSTER_H_</span>
<a name="l00008"></a>00008 <span class="preprocessor"></span>
<a name="l00012"></a><a class="code" href="structcluster__node.html">00012</a> <span class="keyword">struct </span><a class="code" href="structcluster__node.html" title="Nó do cluster.">cluster_node</a> 
<a name="l00013"></a>00013 {
<a name="l00014"></a><a class="code" href="structcluster__node.html#fbbc66175da004fcb51b8541ec392ce5">00014</a>         <span class="keyword">struct </span><a class="code" href="structcluster__node.html" title="Nó do cluster.">cluster_node</a> *<a class="code" href="structcluster__node.html#fbbc66175da004fcb51b8541ec392ce5">next</a>;
<a name="l00015"></a><a class="code" href="structcluster__node.html#eefa52202c56107f4a0b087448fbafb0">00015</a>         <span class="keyword">struct </span><a class="code" href="structcluster__node.html" title="Nó do cluster.">cluster_node</a> *<a class="code" href="structcluster__node.html#eefa52202c56107f4a0b087448fbafb0">prev</a>;
<a name="l00016"></a>00016         
<a name="l00017"></a><a class="code" href="structcluster__node.html#7f6ec5e953944d0fce058aa0490cf8b3">00017</a>         <span class="keywordtype">int</span> <a class="code" href="structcluster__node.html#7f6ec5e953944d0fce058aa0490cf8b3">id</a>; <span class="comment">//Id</span>
<a name="l00018"></a><a class="code" href="structcluster__node.html#6a7ba17a6dfff66ba64359895b90c16e">00018</a>         u32 <a class="code" href="structcluster__node.html#6a7ba17a6dfff66ba64359895b90c16e">vlan_ip</a>; <span class="comment">//IP real;</span>
<a name="l00019"></a>00019         
<a name="l00020"></a>00020         <span class="comment">//Heartbeat timer</span>
<a name="l00021"></a><a class="code" href="structcluster__node.html#69957993737a06530c6d09de347c0348">00021</a>         <span class="keyword">struct </span>timer_list *<a class="code" href="structcluster__node.html#69957993737a06530c6d09de347c0348">hb_timer</a>;
<a name="l00022"></a>00022         
<a name="l00023"></a>00023         
<a name="l00024"></a>00024         
<a name="l00025"></a>00025         
<a name="l00026"></a>00026         <span class="comment">//</span>
<a name="l00027"></a>00027         int (*<a class="code" href="structcluster__node.html#09c5e4b7e8ec3163635d261dffb78d53">hard_start_xmit_old</a>)(<span class="keyword">struct </span>sk_buff *skb, <span class="keyword">struct </span>net_device *<a class="code" href="nlb-driver_8c.html#312f6a236fcec7f8803e170412fb3f86" title="Interface de rede do cluster que sera gerenciada pelo L2LB.">dev</a>);
<a name="l00028"></a><a class="code" href="structcluster__node.html#b789bf729c9245fe33c9dce46c1f92ce">00028</a>         <span class="keywordtype">char</span> *<a class="code" href="structcluster__node.html#b789bf729c9245fe33c9dce46c1f92ce">name</a>; <span class="comment">//Nome</span>
<a name="l00029"></a><a class="code" href="structcluster__node.html#9bf6337f90174816c2b326f289413bb0">00029</a>         <span class="keywordtype">int</span> <a class="code" href="structcluster__node.html#9bf6337f90174816c2b326f289413bb0">weight</a>;     <span class="comment">//Capacidade do servidor</span>
<a name="l00030"></a><a class="code" href="structcluster__node.html#e4b2c3ae76002bbe39d0d86c1ffca58a">00030</a>         <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *<a class="code" href="structcluster__node.html#e4b2c3ae76002bbe39d0d86c1ffca58a">mac</a>; <span class="comment">//MAC real</span>
<a name="l00031"></a>00031 } <a class="code" href="cluster_8h.html#39e3ce09327c335c6a58f152f9d8fbbf" title="Nó do cluster.">my_node</a>;
<a name="l00032"></a>00032 
<a name="l00036"></a><a class="code" href="structcluster.html">00036</a> <span class="keyword">struct </span><a class="code" href="structcluster.html" title="Cluster.">cluster</a> 
<a name="l00037"></a>00037 {
<a name="l00038"></a><a class="code" href="structcluster.html#dc003d7c81ab0cee1802cb6742a2de98">00038</a>         <span class="keyword">struct </span><a class="code" href="structcluster__node.html" title="Nó do cluster.">cluster_node</a> *<a class="code" href="structcluster.html#dc003d7c81ab0cee1802cb6742a2de98">head</a>; <span class="comment">//Primerio elemento da lista circular de servidores do cluster</span>
<a name="l00039"></a><a class="code" href="structcluster.html#32ff08c9fc90846a9ec4eddf4351fac5">00039</a>         <span class="keyword">struct </span><a class="code" href="structcluster__node.html" title="Nó do cluster.">cluster_node</a> *<a class="code" href="structcluster.html#32ff08c9fc90846a9ec4eddf4351fac5">tail</a>; <span class="comment">//Ultimo elemento da lista circular de servidores do cluster</span>
<a name="l00040"></a><a class="code" href="structcluster.html#7ccd7197eb601ffee1b0f6209578e9a2">00040</a>         <span class="keyword">struct </span><a class="code" href="structcluster__node.html" title="Nó do cluster.">cluster_node</a> *<a class="code" href="structcluster.html#7ccd7197eb601ffee1b0f6209578e9a2">my_node</a>; <span class="comment">//Referencia a este servidor do cluster</span>
<a name="l00041"></a><a class="code" href="structcluster.html#0790d37c29c68e44e2e6aa3c0d46bb70">00041</a>         <span class="keyword">struct </span><a class="code" href="structcluster__node.html" title="Nó do cluster.">cluster_node</a> *<a class="code" href="structcluster.html#0790d37c29c68e44e2e6aa3c0d46bb70">next_serving</a>; <span class="comment">//Referencia ao servidor do cluster que irá responder à proxima requisicao ao cluster</span>
<a name="l00042"></a><a class="code" href="structcluster.html#c5a12bfd4d88406ced444aedaf84ed45">00042</a>         <span class="keywordtype">int</span> <a class="code" href="structcluster.html#c5a12bfd4d88406ced444aedaf84ed45">node_count</a>;
<a name="l00043"></a>00043         
<a name="l00044"></a><a class="code" href="structcluster.html#c846f7faaa5552def937e185f42e40e5">00044</a>         <span class="keyword">struct </span>net_device *<a class="code" href="structcluster.html#c846f7faaa5552def937e185f42e40e5">dev</a>; <span class="comment">//Interface de rede do cluster</span>
<a name="l00045"></a><a class="code" href="structcluster.html#5c014dc4806dfdcc72ddcdfff23231ae">00045</a>         <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="structcluster.html#5c014dc4806dfdcc72ddcdfff23231ae">mac_response</a>[ETH_ALEN]; <span class="comment">//MAC address usado nas respostas do servidor</span>
<a name="l00046"></a>00046         
<a name="l00047"></a><a class="code" href="structcluster.html#cdb104ede08b2fbd5bcfb23aa8db042d">00047</a>         <span class="keyword">struct </span>net_device *<a class="code" href="structcluster.html#cdb104ede08b2fbd5bcfb23aa8db042d">vlan_dev</a>; <span class="comment">//Interface de rede da VLAN</span>
<a name="l00048"></a>00048 
<a name="l00049"></a><a class="code" href="structcluster.html#7ae1f275ddabb8b5ff63b6b9dc171a0c">00049</a>         <span class="keywordtype">int</span> <a class="code" href="structcluster.html#7ae1f275ddabb8b5ff63b6b9dc171a0c">port</a>; <span class="comment">//Porta do servico balanceado no cluster</span>
<a name="l00050"></a>00050                 
<a name="l00051"></a>00051         <span class="comment">//Ponteiro para a funcao original que monta o cabecalho do pacote na camada de enlace.</span>
<a name="l00052"></a>00052         <span class="comment">//Ao carregar o modulo NLB, essa funcao sera substituida.</span>
<a name="l00053"></a>00053         <span class="comment">//Ao despachar o modulo NLB, o ponteiro para a funcao original eh restaurada. </span>
<a name="l00054"></a>00054         int (*<a class="code" href="structcluster.html#088588314045ccef65ac5c6b72d5e37d">hard_start_xmit_old</a>)(<span class="keyword">struct </span>sk_buff *skb, <span class="keyword">struct </span>net_device *<a class="code" href="structcluster.html#c846f7faaa5552def937e185f42e40e5">dev</a>);
<a name="l00055"></a>00055         
<a name="l00056"></a>00056         <span class="comment">//IP da interface de rede do cluster.</span>
<a name="l00057"></a>00057         <span class="comment">//Ao carregar o modulo, o IP da interface de rede do cluster eh modificado.</span>
<a name="l00058"></a>00058         <span class="comment">//Por isso, eh necessario armazenar o IP anterior para restaura-lo ao remover o modulo</span>
<a name="l00059"></a><a class="code" href="structcluster.html#823f2ac00f77d6c7f23f224e5d7f328f">00059</a>         u32 <a class="code" href="structcluster.html#823f2ac00f77d6c7f23f224e5d7f328f">ip</a>; 
<a name="l00060"></a><a class="code" href="structcluster.html#e763326a5606306ff8879a318c03e176">00060</a>         <span class="keyword">struct </span>in_ifaddr <a class="code" href="structcluster.html#e763326a5606306ff8879a318c03e176">new_ip_addr</a>;
<a name="l00061"></a>00061         
<a name="l00062"></a>00062         <span class="comment">//Usada para garantir atomicidade nas operacoes de leitura/escritra no cluster</span>
<a name="l00063"></a><a class="code" href="structcluster.html#4918986560ed2638282b9a6856427dda">00063</a>         rwlock_t <a class="code" href="structcluster.html#4918986560ed2638282b9a6856427dda">rwlock</a>;
<a name="l00064"></a>00064         
<a name="l00065"></a>00065 } <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>;
<a name="l00066"></a>00066 
<a name="l00067"></a>00067 <span class="keywordtype">void</span> <a class="code" href="cluster_8h.html#1cacc18d29de69dfe9b47ee4eb5e7600" title="Prepara o servidor adicionado ao cluster para ser removido do cluster se nao receber...">hb_timer_add</a>(<span class="keyword">struct</span> <a class="code" href="structcluster__node.html" title="Nó do cluster.">cluster_node</a> *new_node);
<a name="l00068"></a>00068 <span class="keywordtype">int</span> <a class="code" href="cluster_8h.html#25dbc05b5c8157863bcb1801c17f77c1" title="Envia uma mensagem em Brodcast para todos os nós do cluster.">hb_broadcast_msg</a>(<span class="keywordtype">char</span> *buf, <span class="keywordtype">int</span> buf_len);
<a name="l00069"></a>00069 <span class="keywordtype">void</span> <a class="code" href="cluster_8h.html#28ab4480aefa945c08a4d1f5e16a8d5e" title="Remove todas as afinidades de um servidor Metodo usado na hora de remover um servidor...">hash_remove_node_affinities</a>(<span class="keyword">struct</span> <a class="code" href="structcluster__node.html" title="Nó do cluster.">cluster_node</a> *node);
<a name="l00070"></a>00070 
<a name="l00077"></a><a class="code" href="cluster_8h.html#a568a7669c4ee6f27338231d23575c13">00077</a> <span class="keyword">static</span> <span class="keyword">struct </span><a class="code" href="structcluster__node.html" title="Nó do cluster.">cluster_node</a> *<a class="code" href="cluster_8h.html#a568a7669c4ee6f27338231d23575c13" title="Registra um novo servidor do cluster.">add_cluster_node</a>(<span class="keywordtype">int</span> <span class="keywordtype">id</span>, u32 <a class="code" href="structcluster__node.html#6a7ba17a6dfff66ba64359895b90c16e">vlan_ip</a>)
<a name="l00078"></a>00078 {
<a name="l00079"></a>00079         <span class="keyword">struct </span><a class="code" href="structcluster__node.html" title="Nó do cluster.">cluster_node</a> *new_node;
<a name="l00080"></a>00080         
<a name="l00081"></a>00081         <span class="comment">//Cria a servidor do cluster</span>
<a name="l00082"></a>00082         new_node = (<span class="keyword">struct </span><a class="code" href="structcluster__node.html" title="Nó do cluster.">cluster_node</a> *)kmalloc(<span class="keyword">sizeof</span>(<span class="keyword">struct</span> <a class="code" href="structcluster__node.html" title="Nó do cluster.">cluster_node</a>), GFP_ATOMIC);
<a name="l00083"></a>00083         new_node-&gt;<a class="code" href="structcluster__node.html#7f6ec5e953944d0fce058aa0490cf8b3">id</a> = id;
<a name="l00084"></a>00084         new_node-&gt;<a class="code" href="structcluster__node.html#6a7ba17a6dfff66ba64359895b90c16e">vlan_ip</a> = vlan_ip;
<a name="l00085"></a>00085         
<a name="l00086"></a>00086         write_lock(&amp;<a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#4918986560ed2638282b9a6856427dda">rwlock</a>);
<a name="l00087"></a>00087         
<a name="l00088"></a>00088         <span class="comment">//Inseri o nó na lista circular de servidores</span>
<a name="l00089"></a>00089         <span class="keywordflow">if</span>(<a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#c5a12bfd4d88406ced444aedaf84ed45">node_count</a> == 0) 
<a name="l00090"></a>00090         {
<a name="l00091"></a>00091                 new_node-&gt;<a class="code" href="structcluster__node.html#eefa52202c56107f4a0b087448fbafb0">prev</a> = new_node;
<a name="l00092"></a>00092                 new_node-&gt;<a class="code" href="structcluster__node.html#fbbc66175da004fcb51b8541ec392ce5">next</a> = new_node;
<a name="l00093"></a>00093                 <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#dc003d7c81ab0cee1802cb6742a2de98">head</a> = new_node;
<a name="l00094"></a>00094                 <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#0790d37c29c68e44e2e6aa3c0d46bb70">next_serving</a> = new_node;
<a name="l00095"></a>00095         }
<a name="l00096"></a>00096         <span class="keywordflow">else</span> 
<a name="l00097"></a>00097         {
<a name="l00098"></a>00098                 new_node-&gt;<a class="code" href="structcluster__node.html#eefa52202c56107f4a0b087448fbafb0">prev</a> = <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#32ff08c9fc90846a9ec4eddf4351fac5">tail</a>;
<a name="l00099"></a>00099                 new_node-&gt;<a class="code" href="structcluster__node.html#fbbc66175da004fcb51b8541ec392ce5">next</a> = <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#dc003d7c81ab0cee1802cb6742a2de98">head</a>;
<a name="l00100"></a>00100                 <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#dc003d7c81ab0cee1802cb6742a2de98">head</a>-&gt;<a class="code" href="structcluster__node.html#eefa52202c56107f4a0b087448fbafb0">prev</a> = new_node;
<a name="l00101"></a>00101                 <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#32ff08c9fc90846a9ec4eddf4351fac5">tail</a>-&gt;<a class="code" href="structcluster__node.html#fbbc66175da004fcb51b8541ec392ce5">next</a> = new_node;
<a name="l00102"></a>00102         }
<a name="l00103"></a>00103         
<a name="l00104"></a>00104         <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#32ff08c9fc90846a9ec4eddf4351fac5">tail</a> = new_node;
<a name="l00105"></a>00105         
<a name="l00106"></a>00106         <span class="comment">//Incrementa o número de servidores cadastrados</span>
<a name="l00107"></a>00107         <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#c5a12bfd4d88406ced444aedaf84ed45">node_count</a>++;
<a name="l00108"></a>00108         
<a name="l00109"></a>00109         write_unlock(&amp;<a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#4918986560ed2638282b9a6856427dda">rwlock</a>);
<a name="l00110"></a>00110         
<a name="l00111"></a>00111         <span class="comment">//Prepara o servidor para receber o heartbeat</span>
<a name="l00112"></a>00112         <a class="code" href="cluster_8h.html#1cacc18d29de69dfe9b47ee4eb5e7600" title="Prepara o servidor adicionado ao cluster para ser removido do cluster se nao receber...">hb_timer_add</a>(new_node);
<a name="l00113"></a>00113         
<a name="l00114"></a>00114         <span class="comment">//Retorna uma referencia ao servidor recem criado</span>
<a name="l00115"></a>00115         <span class="keywordflow">return</span> new_node;
<a name="l00116"></a>00116 }
<a name="l00117"></a>00117 
<a name="l00125"></a><a class="code" href="cluster_8h.html#c55a15a79cadec11fb3d6df11ac5f4e7">00125</a> <span class="keywordtype">void</span> <a class="code" href="cluster_8h.html#c55a15a79cadec11fb3d6df11ac5f4e7" title="Remove um servidor do clusterRemove o servidor da lista de servidores,Notifica os...">remove_cluster_node</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> node_ptr)
<a name="l00126"></a>00126 {
<a name="l00127"></a>00127         <span class="keyword">struct </span><a class="code" href="structcluster__node.html" title="Nó do cluster.">cluster_node</a> *node = (<span class="keyword">struct </span><a class="code" href="structcluster__node.html" title="Nó do cluster.">cluster_node</a> *)node_ptr;
<a name="l00128"></a>00128         <span class="keyword">struct </span><a class="code" href="structcluster__node.html" title="Nó do cluster.">cluster_node</a> *node_next = node-&gt;<a class="code" href="structcluster__node.html#fbbc66175da004fcb51b8541ec392ce5">next</a>;
<a name="l00129"></a>00129         <span class="keyword">struct </span><a class="code" href="structcluster__node.html" title="Nó do cluster.">cluster_node</a> *node_prev = node-&gt;<a class="code" href="structcluster__node.html#eefa52202c56107f4a0b087448fbafb0">prev</a>;
<a name="l00130"></a>00130         <span class="keywordtype">char</span> *msg;
<a name="l00131"></a>00131         
<a name="l00132"></a>00132         <span class="comment">//Remove da lista de servidores</span>
<a name="l00133"></a>00133         node_prev-&gt;<a class="code" href="structcluster__node.html#fbbc66175da004fcb51b8541ec392ce5">next</a> = node-&gt;<a class="code" href="structcluster__node.html#fbbc66175da004fcb51b8541ec392ce5">next</a>;
<a name="l00134"></a>00134         node_next-&gt;<a class="code" href="structcluster__node.html#eefa52202c56107f4a0b087448fbafb0">prev</a> = node-&gt;<a class="code" href="structcluster__node.html#eefa52202c56107f4a0b087448fbafb0">prev</a>;
<a name="l00135"></a>00135         
<a name="l00136"></a>00136         write_lock(&amp;<a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#4918986560ed2638282b9a6856427dda">rwlock</a>);
<a name="l00137"></a>00137         
<a name="l00138"></a>00138         <span class="keywordflow">if</span>(<a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#dc003d7c81ab0cee1802cb6742a2de98">head</a> == node)
<a name="l00139"></a>00139                 <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#dc003d7c81ab0cee1802cb6742a2de98">head</a> = node-&gt;<a class="code" href="structcluster__node.html#fbbc66175da004fcb51b8541ec392ce5">next</a>;
<a name="l00140"></a>00140         
<a name="l00141"></a>00141         <span class="keywordflow">if</span>(<a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#32ff08c9fc90846a9ec4eddf4351fac5">tail</a> == node)
<a name="l00142"></a>00142                 <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#32ff08c9fc90846a9ec4eddf4351fac5">tail</a> = node-&gt;<a class="code" href="structcluster__node.html#eefa52202c56107f4a0b087448fbafb0">prev</a>;
<a name="l00143"></a>00143         
<a name="l00144"></a>00144         <span class="keywordflow">if</span>(<a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#0790d37c29c68e44e2e6aa3c0d46bb70">next_serving</a> == node)
<a name="l00145"></a>00145                 <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#0790d37c29c68e44e2e6aa3c0d46bb70">next_serving</a> = node-&gt;<a class="code" href="structcluster__node.html#fbbc66175da004fcb51b8541ec392ce5">next</a>;
<a name="l00146"></a>00146         
<a name="l00147"></a>00147         <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#c5a12bfd4d88406ced444aedaf84ed45">node_count</a>--;
<a name="l00148"></a>00148         
<a name="l00149"></a>00149         <span class="keywordflow">if</span>(<a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#c5a12bfd4d88406ced444aedaf84ed45">node_count</a> == 0)
<a name="l00150"></a>00150         {
<a name="l00151"></a>00151                 <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#dc003d7c81ab0cee1802cb6742a2de98">head</a> = 0;
<a name="l00152"></a>00152                 <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#32ff08c9fc90846a9ec4eddf4351fac5">tail</a> = 0;
<a name="l00153"></a>00153                 <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#0790d37c29c68e44e2e6aa3c0d46bb70">next_serving</a> = 0;
<a name="l00154"></a>00154         }
<a name="l00155"></a>00155         
<a name="l00156"></a>00156         write_unlock(&amp;<a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#4918986560ed2638282b9a6856427dda">rwlock</a>);
<a name="l00157"></a>00157         
<a name="l00158"></a>00158         <span class="comment">//Remove a lista de afinidade</span>
<a name="l00159"></a>00159         <a class="code" href="cluster_8h.html#28ab4480aefa945c08a4d1f5e16a8d5e" title="Remove todas as afinidades de um servidor Metodo usado na hora de remover um servidor...">hash_remove_node_affinities</a>(node);
<a name="l00160"></a>00160         
<a name="l00161"></a>00161         <span class="comment">//Notifica ao cluster a exclusao deste servidor</span>
<a name="l00162"></a>00162         msg = (<span class="keywordtype">char</span> *)kmalloc(1024, GFP_ATOMIC);
<a name="l00163"></a>00163         memset(msg, 0, 1024);
<a name="l00164"></a>00164         sprintf(msg, <span class="stringliteral">"remove-node :%d"</span>, node-&gt;<a class="code" href="structcluster__node.html#7f6ec5e953944d0fce058aa0490cf8b3">id</a>);
<a name="l00165"></a>00165         
<a name="l00166"></a>00166         <a class="code" href="cluster_8h.html#25dbc05b5c8157863bcb1801c17f77c1" title="Envia uma mensagem em Brodcast para todos os nós do cluster.">hb_broadcast_msg</a>(msg, 1024);
<a name="l00167"></a>00167         
<a name="l00168"></a>00168         <span class="comment">//Libera memoria</span>
<a name="l00169"></a>00169         kfree(node);
<a name="l00170"></a>00170         
<a name="l00171"></a>00171         <span class="comment">//</span>
<a name="l00172"></a>00172         printk(KERN_ALERT MODULE_NAME <span class="stringliteral">": Remove node %d\n"</span>, node-&gt;<a class="code" href="structcluster__node.html#7f6ec5e953944d0fce058aa0490cf8b3">id</a>);
<a name="l00173"></a>00173 }
<a name="l00174"></a>00174 
<a name="l00180"></a><a class="code" href="cluster_8h.html#4e116ec9395a6720c5f84de3e28b25a9">00180</a> <span class="keyword">struct </span><a class="code" href="structcluster__node.html" title="Nó do cluster.">cluster_node</a> *<a class="code" href="cluster_8h.html#4e116ec9395a6720c5f84de3e28b25a9" title="Busca um servidor do cluster pelo ID.">get_node_by_id</a>(<span class="keywordtype">int</span> <span class="keywordtype">id</span>) 
<a name="l00181"></a>00181 {
<a name="l00182"></a>00182         <span class="keyword">struct </span><a class="code" href="structcluster__node.html" title="Nó do cluster.">cluster_node</a> *node;
<a name="l00183"></a>00183         
<a name="l00184"></a>00184         read_lock(&amp;<a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#4918986560ed2638282b9a6856427dda">rwlock</a>);
<a name="l00185"></a>00185         
<a name="l00186"></a>00186         node = <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#dc003d7c81ab0cee1802cb6742a2de98">head</a>;
<a name="l00187"></a>00187         
<a name="l00188"></a>00188         <span class="keywordflow">if</span>(node) 
<a name="l00189"></a>00189         {
<a name="l00190"></a>00190                 <span class="keywordflow">do</span> 
<a name="l00191"></a>00191                 {
<a name="l00192"></a>00192                         <span class="keywordflow">if</span>(node-&gt;<a class="code" href="structcluster__node.html#7f6ec5e953944d0fce058aa0490cf8b3">id</a> == <span class="keywordtype">id</span>)
<a name="l00193"></a>00193                         {
<a name="l00194"></a>00194                                 read_unlock(&amp;<a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#4918986560ed2638282b9a6856427dda">rwlock</a>);
<a name="l00195"></a>00195                                 <span class="keywordflow">return</span> node;
<a name="l00196"></a>00196                         }
<a name="l00197"></a>00197                         
<a name="l00198"></a>00198                         node = node-&gt;<a class="code" href="structcluster__node.html#fbbc66175da004fcb51b8541ec392ce5">next</a>;
<a name="l00199"></a>00199                 } <span class="keywordflow">while</span>(node != <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#dc003d7c81ab0cee1802cb6742a2de98">head</a>);
<a name="l00200"></a>00200         }
<a name="l00201"></a>00201         
<a name="l00202"></a>00202         read_unlock(&amp;<a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#4918986560ed2638282b9a6856427dda">rwlock</a>);
<a name="l00203"></a>00203         
<a name="l00204"></a>00204         <span class="keywordflow">return</span> (<span class="keyword">struct</span> <a class="code" href="structcluster__node.html" title="Nó do cluster.">cluster_node</a> *)NULL;
<a name="l00205"></a>00205 }
<a name="l00206"></a>00206 
<a name="l00214"></a><a class="code" href="cluster_8h.html#33d0ab81e5ab7cf05146cead194236b7">00214</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="cluster_8h.html#33d0ab81e5ab7cf05146cead194236b7" title="Inicializa a estrutura my_cluster.">init_cluster</a>(<span class="keywordtype">char</span> *<a class="code" href="nlb-driver_8c.html#312f6a236fcec7f8803e170412fb3f86" title="Interface de rede do cluster que sera gerenciada pelo L2LB.">dev</a>, <span class="keywordtype">char</span> *<a class="code" href="nlb-driver_8c.html#c8f175c78fae68f5348eab7bcc8ca54b" title="IP virtual do cluster.">ip</a>, <span class="keywordtype">int</span> (*hard_start_xmit_new)(<span class="keyword">struct</span> sk_buff *skb, <span class="keyword">struct</span> net_device *dev))
<a name="l00215"></a>00215 {
<a name="l00216"></a>00216         u32 ip_long;
<a name="l00217"></a>00217         
<a name="l00218"></a>00218         <span class="comment">//Obtem referencia a interface de rede usado para o cluster`</span>
<a name="l00219"></a>00219         rwlock_init(&amp;<a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#4918986560ed2638282b9a6856427dda">rwlock</a>);
<a name="l00220"></a>00220         
<a name="l00221"></a>00221         <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#c846f7faaa5552def937e185f42e40e5">dev</a> = dev_get_by_name(dev);
<a name="l00222"></a>00222         <span class="keywordflow">if</span>( !<a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#c846f7faaa5552def937e185f42e40e5">dev</a> ) 
<a name="l00223"></a>00223         {
<a name="l00224"></a>00224                 printk( KERN_ALERT MODULE_NAME <span class="stringliteral">": Cluster device NOT found! %s\n"</span>, dev );
<a name="l00225"></a>00225                 <span class="keywordflow">return</span> -1; 
<a name="l00226"></a>00226         }
<a name="l00227"></a>00227         
<a name="l00228"></a>00228         <span class="comment">//Gera um MAC address maluco para colocar na cabecalho das respostas</span>
<a name="l00229"></a>00229         random_ether_addr((u8 *)&amp;<a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#5c014dc4806dfdcc72ddcdfff23231ae">mac_response</a>);
<a name="l00230"></a>00230         
<a name="l00231"></a>00231         <span class="comment">//Mantem o 3 primeiros bytes do endereco MAC para garantir que o MAC seja do mesmo fabricante   </span>
<a name="l00232"></a>00232         memcpy(&amp;<a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#5c014dc4806dfdcc72ddcdfff23231ae">mac_response</a>, <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#c846f7faaa5552def937e185f42e40e5">dev</a>-&gt;dev_addr, 3);
<a name="l00233"></a>00233         memcpy(&amp;<a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#e763326a5606306ff8879a318c03e176">new_ip_addr</a>, ((<span class="keyword">struct</span> in_device *)<a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#c846f7faaa5552def937e185f42e40e5">dev</a>-&gt;ip_ptr)-&gt;ifa_list, <span class="keyword">sizeof</span>(<span class="keyword">struct</span> in_ifaddr));
<a name="l00234"></a>00234         
<a name="l00235"></a>00235         <a class="code" href="utils_8h.html#7a719668dc1cee29bc80d85386ad478e" title="Parse um endereço IPv4.">parse_ipv4_addr</a>(ip, &amp;ip_long);
<a name="l00236"></a>00236         
<a name="l00237"></a>00237         memcpy(&amp;<a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#e763326a5606306ff8879a318c03e176">new_ip_addr</a>.ifa_local, &amp;ip_long, <span class="keyword">sizeof</span>(u32));
<a name="l00238"></a>00238         memcpy(&amp;<a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#e763326a5606306ff8879a318c03e176">new_ip_addr</a>.ifa_address, &amp;ip_long, <span class="keyword">sizeof</span>(u32));
<a name="l00239"></a>00239         
<a name="l00240"></a>00240         <span class="comment">//printk( KERN_ALERT MODULE_NAME ": %u.%u.%u.%u\n", NIPQUAD(ip_long) );</span>
<a name="l00241"></a>00241         
<a name="l00242"></a>00242         <span class="comment">//Altera a funcao que monta o cabecalho do pacote na camada de enlace para da interface de rede do cluster.</span>
<a name="l00243"></a>00243         <span class="comment">//printk( KERN_ALERT MODULE_NAME ": %u.%u.%u.%u\n", NIPQUAD(((struct in_device *)my_cluster.dev-&gt;ip_ptr)-&gt;ifa_list-&gt;ifa_local) );</span>
<a name="l00244"></a>00244         
<a name="l00245"></a>00245         <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#c846f7faaa5552def937e185f42e40e5">dev</a>-&gt;stop(<a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#c846f7faaa5552def937e185f42e40e5">dev</a>);
<a name="l00246"></a>00246         <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#088588314045ccef65ac5c6b72d5e37d">hard_start_xmit_old</a> = <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#c846f7faaa5552def937e185f42e40e5">dev</a>-&gt;hard_start_xmit;
<a name="l00247"></a>00247         <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#c846f7faaa5552def937e185f42e40e5">dev</a>-&gt;hard_start_xmit = hard_start_xmit_new;
<a name="l00248"></a>00248         <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#c846f7faaa5552def937e185f42e40e5">dev</a>-&gt;open(<a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#c846f7faaa5552def937e185f42e40e5">dev</a>);
<a name="l00249"></a>00249         
<a name="l00250"></a>00250         <span class="comment">//inet_insert_ifa(&amp;my_cluster.new_ip_addr);</span>
<a name="l00251"></a>00251         
<a name="l00252"></a>00252         <span class="comment">//printk( KERN_ALERT MODULE_NAME ": %u.%u.%u.%u\n", NIPQUAD(((struct in_device *)my_cluster.dev-&gt;ip_ptr)-&gt;ifa_list-&gt;ifa_address) );</span>
<a name="l00253"></a>00253         <span class="comment">//printk( KERN_ALERT MODULE_NAME ": %u.%u.%u.%u\n", NIPQUAD(((struct in_device *)my_cluster.dev-&gt;ip_ptr)-&gt;ifa_list-&gt;ifa_local) );</span>
<a name="l00254"></a>00254         
<a name="l00255"></a>00255         <span class="comment">//Inicializa variaveis</span>
<a name="l00256"></a>00256         <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#c5a12bfd4d88406ced444aedaf84ed45">node_count</a> = 0;
<a name="l00257"></a>00257 
<a name="l00258"></a>00258         <span class="comment">//</span>
<a name="l00259"></a>00259         <span class="keywordflow">return</span> 0;
<a name="l00260"></a>00260 }
<a name="l00261"></a>00261 
<a name="l00265"></a><a class="code" href="cluster_8h.html#aa5aa80302607600a63f6b78dc842b75">00265</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="cluster_8h.html#aa5aa80302607600a63f6b78dc842b75" title="Finaliza o cluster.">nlb_cluster_exit</a>(<span class="keywordtype">void</span>)
<a name="l00266"></a>00266 {
<a name="l00267"></a>00267         <span class="keyword">struct </span><a class="code" href="structcluster__node.html" title="Nó do cluster.">cluster_node</a> *node;
<a name="l00268"></a>00268 
<a name="l00269"></a>00269         <span class="comment">//Restaura a funcao original que ira montar o cabecalho dos pacotes na camada </span>
<a name="l00270"></a>00270         <span class="comment">//de enlace para a interface de rede do cluster.</span>
<a name="l00271"></a>00271         <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#c846f7faaa5552def937e185f42e40e5">dev</a>-&gt;stop(<a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#c846f7faaa5552def937e185f42e40e5">dev</a>);
<a name="l00272"></a>00272         <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#c846f7faaa5552def937e185f42e40e5">dev</a>-&gt;hard_start_xmit = <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#088588314045ccef65ac5c6b72d5e37d">hard_start_xmit_old</a>;
<a name="l00273"></a>00273         <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#c846f7faaa5552def937e185f42e40e5">dev</a>-&gt;open(<a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#c846f7faaa5552def937e185f42e40e5">dev</a>);
<a name="l00274"></a>00274 
<a name="l00275"></a>00275         <span class="comment">//inet_del_ifa(&amp;my_cluster.new_ip_addr, 0);     </span>
<a name="l00276"></a>00276         
<a name="l00277"></a>00277         <span class="comment">//Remove os TIMERS do Heartbeat</span>
<a name="l00278"></a>00278         node = <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#dc003d7c81ab0cee1802cb6742a2de98">head</a>;
<a name="l00279"></a>00279         
<a name="l00280"></a>00280         <span class="keywordflow">if</span>(node) 
<a name="l00281"></a>00281         {
<a name="l00282"></a>00282                 <span class="keywordflow">do</span> 
<a name="l00283"></a>00283                 {
<a name="l00284"></a>00284                         del_timer_sync(node-&gt;<a class="code" href="structcluster__node.html#69957993737a06530c6d09de347c0348">hb_timer</a>);
<a name="l00285"></a>00285                         node = node-&gt;<a class="code" href="structcluster__node.html#fbbc66175da004fcb51b8541ec392ce5">next</a>;
<a name="l00286"></a>00286                 } <span class="keywordflow">while</span>(node != <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#dc003d7c81ab0cee1802cb6742a2de98">head</a>);
<a name="l00287"></a>00287         }
<a name="l00288"></a>00288         
<a name="l00289"></a>00289         <span class="comment">//</span>
<a name="l00290"></a>00290         
<a name="l00291"></a>00291         <span class="keywordflow">return</span> 0;
<a name="l00292"></a>00292 }
<a name="l00293"></a>00293 
<a name="l00294"></a>00294 <span class="preprocessor">#endif </span><span class="comment">/*CLUSTER_H_*/</span>
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Gerado em Wed Sep 10 23:05:54 2008 para L2LB por&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
</body>
</html>
